using BSDS.Core.Data.Local;

namespace BSDS.Core.Model.Services.Uploading.DataProviders
{
    public class DataProviderFactory
    {
        private readonly DataFormatRecognizer formatRecongnizer;

        public DataProviderFactory(DataFormatRecognizer formatRecongnizer)
        {
            this.formatRecongnizer = formatRecongnizer;
        }

        public IDataProvider Create(string filename, string entityTypeName) //TODO: should this include entityTypeName?
        {
            var dataFormat = formatRecongnizer.Recognize(filename);
            
            IDataProvider dataProvider;

            if(dataFormat == DataFormat.Xml)
            {
                dataProvider = new XmlDataProvider(filename, entityTypeName, dataFormat);
            }
            else
            {
                dataProvider = new CsvDataDataProvider(filename, entityTypeName, dataFormat);
            }

            dataProvider.Initialize();

            return dataProvider;
        }
    }
}